﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using Yugi.Client.Card.Load;
using Yugi.Client.Card;
using Yugi.Client;
using Yugi.Client.Control;
using Yugi_Gui.Animation;
using Yugi.Client.ViewModel;

namespace Yugi_Gui
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        
        public Window1()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Window1_Loaded);
            this.Closing += new System.ComponentModel.CancelEventHandler(Window1_Closing);
        }

        void Window1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (this.Content is GameLayout)
            {
                ((GameLayout)this.Content).GameLayout_Unloaded();
            }
            else if (this.Content is RoomLayout)
            {
                ((RoomLayout)this.Content).GameLayout_Unloaded();
            }
            else if (this.Content is ExternalLayout)
            {
                ((ExternalLayout)this.Content).GameLayout_Unloaded();
            }

        }

       

        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                MainServerHandler mainserver = new MainServerHandler(this, false);
                mainserver.Connect();
                this.DataContext = mainserver;
	            LayoutManager.LayoutManager.MainWindow = this;
	            LayoutManager.LayoutManager.Insitance.ChangeToLayout(LayoutManager.LayoutType.Login);
                Window_SizeChanged(this, null);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            try
            {
                LoginLayout uc = (LoginLayout)this.Content;
                if (uc != null)
                {
                    uc.LayoutRoot.Width = this.Width;
                    uc.LayoutRoot.Height = this.Height;
                }
            }
            catch { }
        }

        private void Window_StateChanged(object sender, EventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                
            }
            else if(this.WindowState == WindowState.Normal)
            {
            }
        }

     
      
    }
}
